﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KhaoSatSinhVienTotNghiep.Model
{
    public partial class CauTL
    {
        private static KhaoSatSVTNDataContext context = new KhaoSatSVTNDataContext();
        public static bool AddNew(CauTL entity)
        {
            try
            {
                context.CauTLs.InsertOnSubmit(entity);
                context.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        public static List<CauTL> GetAll()
        {
            return context.CauTLs.ToList();
        }
        public static List<CauTL> GetByIDCauHoi(int idcauhoi)
        {
            return context.CauTLs.Where(idch => idch.MaCauHoi == idcauhoi).ToList();
        }

        public static bool DeleteCauTL(int id)
        {
            CauTL ctl=GetByID(id);
            context.CauTLs.DeleteOnSubmit(ctl);
            context.SubmitChanges();
            return true;
        }

        public static CauTL GetByID(int id)
        {
            return context.CauTLs.Where(ctl => ctl.MaCauTL == id).FirstOrDefault();
        }
    }
}
